package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatHistoryAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatHistoryListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatHistoryUpdDto;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatHistoryInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatHistoryListVo;
import com.xinzhidi.web.netty.service.AgreementHeatHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 户用、单元热量协议-历史数据Controller
 *
 * @author cx
 * @date 2023-06-17
 */
@RestController
@Api(tags = "户用、单元热量协议-历史数据")
@RequestMapping("/agreement_heat_history")
public class AgreementHeatHistoryController extends BaseController {
    @Autowired
    private AgreementHeatHistoryService agreementHeatHistoryService;

    @ApiOperation("查询户用、单元热量协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:list')")
    @PostMapping("/listAgreementHeatHistory")
    public TableDataInfo<AgreementHeatHistoryListVo> listAgreementHeatHistory(@Validated @RequestBody AgreementHeatHistoryListDto dto) {
        startPagePost(dto);
        return agreementHeatHistoryService.selectAgreementHeatHistoryList(dto);
    }

    @ApiOperation("导出户用、单元热量协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:export')")
    @Log(title = "户用、单元热量协议-历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementHeatHistory")
    public void exportAgreementHeatHistory(HttpServletResponse response, AgreementHeatHistoryListDto dto) {
        TableDataInfo<AgreementHeatHistoryListVo> list = agreementHeatHistoryService.selectAgreementHeatHistoryList(dto);
        ExcelUtil<AgreementHeatHistoryListVo> util = new ExcelUtil<AgreementHeatHistoryListVo>(AgreementHeatHistoryListVo.class);
        util.exportExcel(response, list.getRows(), "户用、单元热量协议-历史数据数据");
    }

    @ApiOperation("获取户用、单元热量协议-历史数据详细信息")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:query')")
    @GetMapping(value = "/getAgreementHeatHistoryById")
    public R<AgreementHeatHistoryInfoVo> getAgreementHeatHistoryById(@RequestParam("id") Long id) {
        return R.ok(agreementHeatHistoryService.selectAgreementHeatHistoryById(id));
    }

    @ApiOperation("新增户用、单元热量协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:add')")
    @Log(title = "户用、单元热量协议-历史数据", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementHeatHistory")
    public AjaxResult addAgreementHeatHistory(@Validated @RequestBody AgreementHeatHistoryAddDto dto) {
        return toAjax(agreementHeatHistoryService.insertAgreementHeatHistory(dto));
    }

    @ApiOperation("修改户用、单元热量协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:edit')")
    @Log(title = "户用、单元热量协议-历史数据", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementHeatHistory")
    public AjaxResult editAgreementHeatHistory(@Validated @RequestBody AgreementHeatHistoryUpdDto dto) {
        return toAjax(agreementHeatHistoryService.updateAgreementHeatHistory(dto));
    }

    @ApiOperation("删除户用、单元热量协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreement_heat_history:agreement_heat_history:remove')")
    @Log(title = "户用、单元热量协议-历史数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementHeatHistory")
    public AjaxResult delAgreementHeatHistory(@RequestParam Long[] ids) {
        return toAjax(agreementHeatHistoryService.deleteAgreementHeatHistoryByIds(ids));
    }
}
